package com.loongtech.bi.manager.game;

import com.loongtech.bi.entity.game.EntityActiveUserAddcashProduce;
import com.loongtech.bi.entity.game.EntityActiveUserCurrencyConsumeUsernum;
import com.loongtech.bi.entity.game.EntityActiveUserCurrencyProduceUsernum;
import com.loongtech.bi.entity.game.EntityRemainCurrency;
import com.loongtech.bi.entity.player.EntityDau;
import com.loongtech.bi.manager.player.DauManager;
import com.loongtech.bi.manager.system.GameParamConfigManager;
import com.loongtech.bi.support.CommonGameParam;
import com.loongtech.bi.support.chart.ChartData1;
import com.loongtech.bi.support.chart.ChartFlow;
import com.loongtech.bi.support.chart.ChartSelect;
import com.loongtech.core.jpa.manager.ManagerQueryCacheBase;
import com.loongtech.core.util.NumberUtil;
import com.loongtech.core.util.Time;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * 游戏内分析-经济分析manager
 * 
 * @author lihui
 * @date 2015-09-15
 */
@Service
public class EconomyGameManager extends ManagerQueryCacheBase<Object> {
	private static final long serialVersionUID = 1L;
	
	@Autowired
	private DauManager dauManager;
	@Autowired
	private ActiveUserAddcashProduceManager activeUserAddcashProduceManager;
	@Autowired
	private ActiveUserCurrencyProduceManager activeUserCurrencyProduceManager;
	@Autowired
	private ActiveUserCurrencyProduceUsernumManager activeUserCurrencyProduceUsernumManager;
	@Autowired
	private ActiveUserCurrencyConsumeManager activeUserCurrencyConsumeManager;
	@Autowired
	private ActiveUserCurrencyConsumeUsernumManager activeUserCurrencyConsumeUsernumManager;
	@Autowired
	private ActiveUserCurrencyProduceReasonManager activeUserCurrencyProduceReasonManager;
	@Autowired
	private ActiveUserCurrencyConsumeReasonManager activeUserCurrencyConsumeReasonManager;
	@Autowired
    private RemainCurrencyManager remainCurrencyManager;

	//查询消耗途径
	public List<YuanbaoConsumeData> getListYuanbaoConsumeData(Date dateStart, Date dateEnd, String queryPlatform, String queryChannel, String queryServer,String currencytype) {
		List<YuanbaoConsumeData> result = new ArrayList<>();
		//消耗原因
		List<Object[]> listCurrencyConsumeReason = activeUserCurrencyConsumeReasonManager.getData(dateStart, dateEnd, queryPlatform, queryChannel, queryServer, currencytype);
		
		//游戏消耗元宝
		List<Long> currencyConsumeList = activeUserCurrencyConsumeManager.getSumData(dateStart, dateEnd, queryPlatform, queryChannel, queryServer,currencytype);
		//游戏消耗人数
		List<EntityActiveUserCurrencyConsumeUsernum> currencyConsumeUserList = activeUserCurrencyConsumeUsernumManager.getData(dateStart, dateEnd, queryPlatform, queryChannel, queryServer, currencytype);
		
		for(Object[] o : listCurrencyConsumeReason) {
			YuanbaoConsumeData yuanbaoConsumeData = new YuanbaoConsumeData();
			yuanbaoConsumeData.setConsumeWay(String.valueOf(o[0]));
			yuanbaoConsumeData.setConsumeWayStr(getWayStr("-" + String.valueOf(o[0])));
			yuanbaoConsumeData.setConsumeCount(-NumberUtil.parseLong(o[1]));
			yuanbaoConsumeData.setConsumeUser(NumberUtil.parseLong(o[2]));
			
			//消耗占比
			if(currencyConsumeList.size() > 0) {
				Float outputCountRadio = NumberUtil.parseLong(o[1]) / currencyConsumeList.get(0).floatValue();
				yuanbaoConsumeData.setConsumeCountRadio(outputCountRadio);
			}
			
			//人数占比
			if(currencyConsumeUserList.size() > 0) {
				EntityActiveUserCurrencyConsumeUsernum e = currencyConsumeUserList.get(0);
				Float outputUserRadio = NumberUtil.parseLong(o[2]) / e.getUsernum().floatValue();
				yuanbaoConsumeData.setConsumeUserRadio(outputUserRadio);
			}
			
			result.add(yuanbaoConsumeData);
		}
		
		return result;
	}

	//查询元宝产出量数据
	public List<YuanbaoOutputData> getListYuanbaoOutputData(Date dateStart, Date dateEnd, String queryPlatform, String queryChannel, String queryServer,String currencytype) {
		List<YuanbaoOutputData> result = new ArrayList<>();
		//产出原因
		List<Object[]> listCurrencyProduceReason = activeUserCurrencyProduceReasonManager.getData(dateStart, dateEnd, queryPlatform, queryChannel, queryServer, currencytype);
		
		//游戏产出元宝
		List<Long> currencyProduceList = activeUserCurrencyProduceManager.getSumData(dateStart, dateEnd, queryPlatform, queryChannel, queryServer,currencytype);
		//游戏产出人数
		List<EntityActiveUserCurrencyProduceUsernum> currencyProduceUserList = activeUserCurrencyProduceUsernumManager.getData(dateStart, dateEnd, queryPlatform, queryChannel, queryServer, currencytype);

		for(Object[] o : listCurrencyProduceReason) {
			YuanbaoOutputData yuanbaoOutputData = new YuanbaoOutputData();
			yuanbaoOutputData.setOutputWay(String.valueOf(o[0]));
			yuanbaoOutputData.setOutputCount(NumberUtil.parseLong(o[1]));
			yuanbaoOutputData.setOutputUser(NumberUtil.parseLong(o[2]));
			
			//产出占比
			if(currencyProduceList.size() > 0) {
				Float outputCountRadio = NumberUtil.parseLong(o[1]) / currencyProduceList.get(0).floatValue();
				yuanbaoOutputData.setOutputCountRadio(outputCountRadio);
			}
			
			//人数占比
			if(currencyProduceUserList.size() > 0) {
				EntityActiveUserCurrencyProduceUsernum e = currencyProduceUserList.get(0);
				Float outputUserRadio = NumberUtil.parseLong(o[2]) / e.getUsernum().floatValue();
				yuanbaoOutputData.setOutputUserRadio(outputUserRadio);
			}
			
			result.add(yuanbaoOutputData);
		}
		
		return result;
	}
	
	//查询所有元宝数据
	public List<YuanbaoData> getAllYuanbaoData(Date dateStart, Date dateEnd, String queryPlatform, String queryChannel, String queryServer,String currencytype) {
		List<YuanbaoData> result = new ArrayList<>();
		
		List<EntityDau> dauList = dauManager.getAllDauByAllKind(dateStart, dateEnd, queryPlatform, queryChannel, queryServer);
		YuanbaoData yuanbaoData = new YuanbaoData();
		
		//dau
		for(EntityDau o : dauList) {
			yuanbaoData.setActiveUser(o.getDau());
		}
		
		//充值产出
		List<EntityActiveUserAddcashProduce> addcashProduceList = activeUserAddcashProduceManager.getData(dateStart, dateEnd, queryPlatform, queryChannel, queryServer);
		for(EntityActiveUserAddcashProduce o : addcashProduceList) {
			yuanbaoData.setAddcashProduceUsernum(o.getUsernum());
			yuanbaoData.setAddcashProduceYuanbao(o.getSumyuanbaoadd());
		}
		
		//游戏产出元宝
		List<Long> currencyProduceList = activeUserCurrencyProduceManager.getSumData(dateStart, dateEnd, queryPlatform, queryChannel, queryServer,currencytype);
		for(Long o : currencyProduceList) {
			yuanbaoData.setGameProduceYuanbao(o);
		}
		
		//游戏产出人数
		List<EntityActiveUserCurrencyProduceUsernum> currencyProduceUserList = activeUserCurrencyProduceUsernumManager.getData(dateStart, dateEnd, queryPlatform, queryChannel, queryServer, currencytype);
		for(EntityActiveUserCurrencyProduceUsernum o : currencyProduceUserList) {
			yuanbaoData.setGameProduceUsernum(o.getUsernum());
		}
		
		//游戏消耗元宝
		List<Long> currencyConsumeList = activeUserCurrencyConsumeManager.getSumData(dateStart, dateEnd, queryPlatform, queryChannel, queryServer, currencytype);
		for(Long o : currencyConsumeList) {
			yuanbaoData.setYuanbaoConsumeCount(-o);
		}
		
		//游戏消耗人数
		List<EntityActiveUserCurrencyConsumeUsernum> currencyConsumeUserList = activeUserCurrencyConsumeUsernumManager.getData(dateStart, dateEnd, queryPlatform, queryChannel, queryServer, currencytype);
		for(EntityActiveUserCurrencyConsumeUsernum o : currencyConsumeUserList) {
			yuanbaoData.setYuabbaoConsumeUser(o.getUsernum());
		}
		
		//如果不为0
		if(yuanbaoData.getActiveUser() != 0) {
			long avgYuabbaoRemainCount = 
					(yuanbaoData.getAddcashProduceYuanbao() + yuanbaoData.getGameProduceYuanbao() - 
							yuanbaoData.getYuanbaoConsumeCount()) / yuanbaoData.getActiveUser();
			
			yuanbaoData.setAvgYuabbaoRemainCount(avgYuabbaoRemainCount);
		}
		
		result.add(yuanbaoData);
		return result;
	}

	//查询元宝数据列表
	public List<YuanbaoData> getListYuanbaoData(Date dateStart, Date dateEnd, String queryPlatform, String queryChannel, String queryServer,String currencytype) {
		List<YuanbaoData> result = new ArrayList<YuanbaoData>();
		//map
		Map<String,YuanbaoData> map = new HashMap<String,YuanbaoData>();
		
		List<EntityDau> dauList = dauManager.getDauByAllKind(dateStart, dateEnd, queryPlatform, queryChannel, queryServer);
	
		//dau
		for(EntityDau o : dauList) {
			YuanbaoData yuanbaoData = new YuanbaoData();
			yuanbaoData.setDateStr(o.getStartday());
			yuanbaoData.setActiveUser(o.getDau());

			//map 存入
			map.put(o.getStartday(), yuanbaoData);
		}
		
		//充值产出
		List<EntityActiveUserAddcashProduce> addcashProduceList = activeUserAddcashProduceManager.getListData(dateStart, dateEnd, queryPlatform, queryChannel, queryServer);
		for(EntityActiveUserAddcashProduce o : addcashProduceList) {
			YuanbaoData yuanbaoData = map.get(o.getStartday());
			
			if(yuanbaoData != null) {
				yuanbaoData.setAddcashProduceUsernum(o.getUsernum());
				yuanbaoData.setAddcashProduceYuanbao(o.getSumyuanbaoadd());
				
				//map 存入
				map.put(o.getStartday(), yuanbaoData);
			}
		}
		
		//游戏产出元宝
		List<Object[]> currencyProduceList = activeUserCurrencyProduceManager.getListData(dateStart, dateEnd, queryPlatform, queryChannel, queryServer,currencytype);
		for(Object[] o : currencyProduceList) {
			YuanbaoData yuanbaoData = map.get(o[0].toString());
			if(yuanbaoData != null) {
				yuanbaoData.setGameProduceYuanbao(NumberUtil.parseLong(o[1]));
			}
		}
		
		//游戏产出人数
		List<Object[]> currencyProduceUserList = activeUserCurrencyProduceUsernumManager.getListData(dateStart, dateEnd, queryPlatform, queryChannel, queryServer, currencytype);
		for(Object[] o : currencyProduceUserList) {
			YuanbaoData yuanbaoData = map.get(o[0].toString());
			if(yuanbaoData != null) {
				yuanbaoData.setGameProduceUsernum(NumberUtil.parseInt(o[1]));
			}
		}
		
		//游戏消耗元宝
		List<Object[]> currencyConsumeList = activeUserCurrencyConsumeManager.getListData(dateStart, dateEnd, queryPlatform, queryChannel, queryServer, currencytype);
		for(Object[] o : currencyConsumeList) {
			YuanbaoData yuanbaoData = map.get(o[0].toString());
			if(yuanbaoData != null) {
				yuanbaoData.setYuanbaoConsumeCount(-NumberUtil.parseInt(o[1]));
			}
		}
		
		//游戏消耗人数
		List<Object[]> currencyConsumeUserList = activeUserCurrencyConsumeUsernumManager.getListData(dateStart, dateEnd, queryPlatform, queryChannel, queryServer, currencytype);
		for(Object[] o : currencyConsumeUserList) {
			YuanbaoData yuanbaoData = map.get(o[0].toString());
			if(yuanbaoData != null) {
				yuanbaoData.setYuabbaoConsumeUser(NumberUtil.parseInt(o[1]));
			}
		}
		
		//人均元宝存量
		for (Map.Entry<String,YuanbaoData> entry : map.entrySet()) {
			YuanbaoData yuanbaoData = entry.getValue();
			//累计元宝存量
			long totalYuanbaoLeft = yuanbaoData.getAddcashProduceYuanbao() + yuanbaoData.getGameProduceYuanbao() -
					yuanbaoData.getYuanbaoConsumeCount();
			yuanbaoData.setTotalYuanbaoLeft(totalYuanbaoLeft);
			//如果不为0
			if(yuanbaoData.getActiveUser() != 0) {
				long avgYuabbaoRemainCount = 
						(yuanbaoData.getAddcashProduceYuanbao() + yuanbaoData.getGameProduceYuanbao() - 
								yuanbaoData.getYuanbaoConsumeCount()) / yuanbaoData.getActiveUser();
				
				yuanbaoData.setAvgYuabbaoRemainCount(avgYuabbaoRemainCount);
			}
		}
		
		//遍历存入结果
		for(EntityDau o : dauList) {
			YuanbaoData yuanbaoData = map.get(o.getStartday());
			
			if(yuanbaoData != null) {
				result.add(yuanbaoData);
			}
		}
		
		return result;
	}
	
	public List<YuanbaoConsumeData> getYuanbaoConsumeData(Date dateStart, Date dateEnd, String queryPlatform, String queryChannel, String queryServer) {
		List<YuanbaoConsumeData> result = new ArrayList<>();
		
		for (int i = 1; i < 6; i++) {
			YuanbaoConsumeData o = new YuanbaoConsumeData();
			o.setConsumeWay("途径" + i);
			o.setConsumeCount((long)(Math.random() * 1000 + 200));
			o.setConsumeCountRadio((float)(Math.random() * 1000 + 200));
			o.setConsumeUser((long)(Math.random() * 1000 + 200));
			o.setConsumeUserRadio((float)(Math.random() * 1000 + 200));
			
			result.add(o);
		}
		
		return result;
	}
	
	// 元宝数据类和chart类
	public class YuanbaoData {
		@ChartFlow(name="日期")
		private String dateStr; // 日期
		private int activeUser;  // 活跃人数
		
		@ChartSelect(name = "元宝产出&消耗量", key = 1)
		@ChartData1(name = "充值产出元宝", key = 1)
		private long addcashProduceYuanbao; //充值产出元宝
		@ChartSelect(name = "元宝产出&消耗人数", key = 2)
		@ChartData1(name = "充值产出人数", key = 2)
		private long addcashProduceUsernum; //充值产出人数
		@ChartData1(name = "游戏产出元宝", key = 1)
		private long gameProduceYuanbao; //游戏产出元宝
		@ChartData1(name = "游戏产出人数", key = 2)
		private long gameProduceUsernum; //游戏产出人数
		@ChartData1(name = "元宝消耗量", key = 1)
		private long yuanbaoConsumeCount; // 元宝消耗量
		@ChartData1(name = "元宝消耗人数", key = 2)
		private long yuabbaoConsumeUser; // 元宝消耗人数
		@ChartSelect(name = "人均元宝剩余量", key = 4)
		@ChartData1(name = "人均元宝剩余量", key = 4)
		private long avgYuabbaoRemainCount; // 人均元宝剩余量（累积元宝存量/活跃人数）
		@ChartSelect(name = "累计元宝存量", key = 3)
		@ChartData1(name = "累计元宝存量", key = 3)
		private long totalYuanbaoLeft; //累计元宝存量

		public String getDateStr() {
			return dateStr;
		}

		public void setDateStr(String dateStr) {
			this.dateStr = dateStr;
		}

		public int getActiveUser() {
			return activeUser;
		}

		public void setActiveUser(int activeUser) {
			this.activeUser = activeUser;
		}

		public long getAddcashProduceYuanbao() {
			return addcashProduceYuanbao;
		}

		public void setAddcashProduceYuanbao(long addcashProduceYuanbao) {
			this.addcashProduceYuanbao = addcashProduceYuanbao;
		}

		public long getAddcashProduceUsernum() {
			return addcashProduceUsernum;
		}

		public void setAddcashProduceUsernum(long addcashProduceUsernum) {
			this.addcashProduceUsernum = addcashProduceUsernum;
		}

		public long getGameProduceYuanbao() {
			return gameProduceYuanbao;
		}

		public void setGameProduceYuanbao(long gameProduceYuanbao) {
			this.gameProduceYuanbao = gameProduceYuanbao;
		}

		public long getGameProduceUsernum() {
			return gameProduceUsernum;
		}

		public void setGameProduceUsernum(long gameProduceUsernum) {
			this.gameProduceUsernum = gameProduceUsernum;
		}

		public long getYuanbaoConsumeCount() {
			return yuanbaoConsumeCount;
		}

		public void setYuanbaoConsumeCount(long yuanbaoConsumeCount) {
			this.yuanbaoConsumeCount = yuanbaoConsumeCount;
		}

		public long getYuabbaoConsumeUser() {
			return yuabbaoConsumeUser;
		}

		public void setYuabbaoConsumeUser(long yuabbaoConsumeUser) {
			this.yuabbaoConsumeUser = yuabbaoConsumeUser;
		}

		public long getAvgYuabbaoRemainCount() {
			return avgYuabbaoRemainCount;
		}

		public void setAvgYuabbaoRemainCount(long avgYuabbaoRemainCount) {
			this.avgYuabbaoRemainCount = avgYuabbaoRemainCount;
		}

		public long getTotalYuanbaoLeft() {
			return totalYuanbaoLeft;
		}

		public void setTotalYuanbaoLeft(long totalYuanbaoLeft) {
			this.totalYuanbaoLeft = totalYuanbaoLeft;
		}
	}
	
	// 元宝产出数据类，chart类
	public class YuanbaoOutputData {
		@ChartFlow(name="产出途径")
		private String outputWay; // 产出途径
		@ChartSelect(name = "产出量", key = 1)
		@ChartData1(name = "产出量", key = 1)
		private long outputCount; // 产出量
		private float outputCountRadio; // 产出占比
		@ChartSelect(name = "产出人数", key = 2)
		@ChartData1(name = "产出人数", key = 2)
		private long outputUser; // 产出人数
		private float outputUserRadio; // 产出人数占比

		public String getOutputWay() {
			return outputWay;
		}

		public void setOutputWay(String outputWay) {
			this.outputWay = outputWay;
		}

		public long getOutputCount() {
			return outputCount;
		}

		public void setOutputCount(long outputCount) {
			this.outputCount = outputCount;
		}

		public float getOutputCountRadio() {
			return outputCountRadio;
		}

		public void setOutputCountRadio(float outputCountRadio) {
			this.outputCountRadio = outputCountRadio;
		}

		public long getOutputUser() {
			return outputUser;
		}

		public void setOutputUser(long outputUser) {
			this.outputUser = outputUser;
		}

		public float getOutputUserRadio() {
			return outputUserRadio;
		}

		public void setOutputUserRadio(float outputUserRadio) {
			this.outputUserRadio = outputUserRadio;
		}
	}


    public String getWayStr(String key) {
        return (GameParamConfigManager.getItemsRevise(CommonGameParam.RMB_REASON).get(key) == null) ? key : GameParamConfigManager.getItemsRevise(CommonGameParam.RMB_REASON).get(key);
    }

	// 元宝消耗数据类，chart类
	public class YuanbaoConsumeData {
		private String consumeWay; // 消耗途径
        @ChartFlow(name="消耗途径")
        private String consumeWayStr;
		@ChartSelect(name = "消耗量", key = 1)
		@ChartData1(name = "消耗量", key = 1)
		private long consumeCount; // 消耗量
		private float consumeCountRadio; // 消耗占比
		@ChartSelect(name = "消耗人数", key = 2)
		@ChartData1(name = "消耗人数", key = 2)
		private long consumeUser; // 消耗人数
		private float consumeUserRadio; // 消耗人数占比

        public final Comparator<YuanbaoConsumeData> comparatorConsumeUser = new Comparator<YuanbaoConsumeData>() {
            public int compare(YuanbaoConsumeData s1, YuanbaoConsumeData s2) {
                return Long.valueOf(s2.getConsumeUser()).compareTo(Long.valueOf(s1.getConsumeUser()));
            }
        };

        public final Comparator<YuanbaoConsumeData> comparatorConsumeCount = new Comparator<YuanbaoConsumeData>() {
            public int compare(YuanbaoConsumeData s1, YuanbaoConsumeData s2) {
                return Long.valueOf(s2.getConsumeCount()).compareTo(Long.valueOf(s1.getConsumeCount()));
            }
        };

		public String getConsumeWay() {
			return consumeWay;
		}

		public void setConsumeWay(String consumeWay) {
			this.consumeWay = consumeWay;
		}

		public long getConsumeCount() {
			return consumeCount;
		}

		public void setConsumeCount(long consumeCount) {
			this.consumeCount = consumeCount;
		}

		public float getConsumeCountRadio() {
			return consumeCountRadio;
		}

		public void setConsumeCountRadio(float consumeCountRadio) {
			this.consumeCountRadio = consumeCountRadio;
		}

		public long getConsumeUser() {
			return consumeUser;
		}

		public void setConsumeUser(long consumeUser) {
			this.consumeUser = consumeUser;
		}

		public float getConsumeUserRadio() {
			return consumeUserRadio;
		}

		public void setConsumeUserRadio(float consumeUserRadio) {
			this.consumeUserRadio = consumeUserRadio;
		}

        public String getConsumeWayStr() {
            return consumeWayStr;
        }

        public void setConsumeWayStr(String consumeWayStr) {
            this.consumeWayStr = consumeWayStr;
        }
    }

    public List<YuanbaoSumData> getYuanbaoSumDatas(Date dateStart, Date dateEnd, String queryPlatform, String queryChannel, String queryServer,String queryCurType) {
        Map<String,YuanbaoSumData> tmpResult = new HashMap<>();

        String preStr = GameParamConfigManager.getItemsRevise(CommonGameParam.ECONOMY_YUAN_BAO_ID).get(queryCurType);

        //游戏产出元宝
        List<Object[]> currencyProduceList = activeUserCurrencyProduceManager.getListData(dateStart, dateEnd, queryPlatform, queryChannel, queryServer,queryCurType);
        for(Object[] o : currencyProduceList) {
            String date = o[0].toString();

            YuanbaoSumData data = tmpResult.get(date);
            if(data == null) {
                data = new YuanbaoSumData();
                data.setDay(date);
                data.setPlatformId(queryPlatform);
                data.setChannelId(queryChannel);
                data.setServerId(queryServer);
                data.setPreStr(preStr);

                tmpResult.put(date, data);
            }
            data.setAdd(NumberUtil.parseInt(o[1]));
        }

        //游戏消耗元宝
        List<Object[]> currencyConsumeList = activeUserCurrencyConsumeManager.getListData(dateStart, dateEnd, queryPlatform, queryChannel, queryServer, queryCurType);
        for(Object[] o : currencyConsumeList) {
            String date = o[0].toString();

            YuanbaoSumData data = tmpResult.get(date);
            if(data == null) {
                data = new YuanbaoSumData();
                data.setDay(date);
                data.setPlatformId(queryPlatform);
                data.setChannelId(queryChannel);
                data.setServerId(queryServer);
                data.setPreStr(preStr);

                tmpResult.put(date, data);
            }
            data.setPlus(-1 * NumberUtil.parseInt(o[1]));
        }

        queryCurType = preStr.contains("非") ? "3" : "2";
        List<EntityRemainCurrency> rests = remainCurrencyManager.getData(dateStart, dateEnd, queryPlatform, queryChannel, queryServer, queryCurType);
        for (EntityRemainCurrency rest : rests) {
            String date = Time.getDateStr(rest.getDay());

            YuanbaoSumData data = tmpResult.get(date);
            if(data == null) {
                data = new YuanbaoSumData();
                data.setDay(date);
                data.setPlatformId(queryPlatform);
                data.setChannelId(queryChannel);
                data.setServerId(queryServer);
                data.setPreStr(preStr);

                tmpResult.put(date, data);
            }
            data.setRest(rest.getRemain());
        }

        ArrayList<YuanbaoSumData> result = new ArrayList<>(tmpResult.values());
        Collections.sort(result, new YuanbaoSumData().comparatorDate);

        return result;
    }

    public class YuanbaoSumData {
        private String platformId;
        private String channelId;
        private String serverId;
        @ChartFlow(name="日期")
        private String day;
        private String preStr;
        @ChartSelect(name = "产出", key = 1)
        @ChartData1(name = "产出", key = 1, legendPrefix="preStr")
        private long add;
        @ChartData1(name = "消耗", key = 1, legendPrefix="preStr")
        private long plus;
        @ChartData1(name = "剩余", key = 1, legendPrefix="preStr")
        private long rest;

        public final Comparator<YuanbaoSumData> comparatorDate = new Comparator<YuanbaoSumData>() {
            public int compare(YuanbaoSumData s1, YuanbaoSumData s2) {
                return s2.getDay().compareTo(s1.getDay());
            }
        };

        public String getPlatformId() {
            return platformId;
        }

        public void setPlatformId(String platformId) {
            this.platformId = platformId;
        }

        public String getChannelId() {
            return channelId;
        }

        public void setChannelId(String channelId) {
            this.channelId = channelId;
        }

        public String getServerId() {
            return serverId;
        }

        public void setServerId(String serverId) {
            this.serverId = serverId;
        }

        public String getDay() {
            return day;
        }

        public void setDay(String day) {
            this.day = day;
        }

        public String getPreStr() {
            return preStr;
        }

        public void setPreStr(String preStr) {
            this.preStr = preStr;
        }

        public long getAdd() {
            return add;
        }

        public void setAdd(long add) {
            this.add = add;
        }

        public long getPlus() {
            return plus;
        }

        public void setPlus(long plus) {
            this.plus = plus;
        }

        public long getRest() {
            return rest;
        }

        public void setRest(long rest) {
            this.rest = rest;
        }
    }
}
